function X = my_cordic(u,z,n)
    X = zeros(1,n);
    x = 1;
    y = 0;

    x = get_K(n)*x;
    for i = 0:n-1,
        d = sign(z);
        
        x_prev = x;
        x = x_prev - (y*d*(2^-i));
        y = y + (x_prev*d*(2^-i));
        z = z - (d*(atan(2^-i))*180/pi);
        
        T = [x -y;y x]*[real(u);imag(u)];
        X(i+1) = T(1)+T(2)*1i;
    end
end

function K = get_K(n)
    K = 1;
    for i=1:n,
        K = K*cos(atan(2^-(i-1)));
    end
end

function d = sign(z)
    if z >= 0
        d = 1;
    else
        d = -1;
    end
end